package com.yuneec.droneservice.command;

import com.MAVLink.yuneec.msg_mav_rc_cmd_ack;
import com.yuneec.droneservice.request.IResponse;

/**
 * Created by gjw on 2017/3/27.
 */

public class TransFileData extends BaseCommand {
    private short[] raw;

    public TransFileData(int seq, byte[] data) {
        this(seq, data, 0, data.length);
    }

    public TransFileData(int seq, byte[] data, int off, int len) {
        super(MAV_RC_COMMAND.MAV_RC_CMD_TRANSFILEDATA);
        if (data == null || off < 0 || len <= 0 || off + len > data.length) {
            throw new IllegalArgumentException();
        }
        raw = new short[len + 2];
        raw[0] = (byte) (seq & 0xFF);
        raw[1] = (byte) ((seq >> 8) & 0xFF);
        byteArrayToUIntArray(raw, 2, raw.length - 2, data, off, len);
    }

    public int getSeq() {
        return (raw[0] | (raw[1] << 8)) & 0xFFFF;
    }

    @Override
    protected short[] body() {
        return raw;
    }

    @Override
    protected boolean forceCompress() {
        return false;
    }

    @Override
    public IResponse toResponse(msg_mav_rc_cmd_ack ack) {
        int code = ack.code;
        return new IResponse(ids(), code);
    }

    @Override
    public boolean hasReply() {
        return true;
    }

}
